package com.atguigu.publisher1.service.impl;

import com.atguigu.publisher1.mappers.ProductStatsMapper;
import com.atguigu.publisher1.service.ProductStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductStatsServiceImpl implements ProductStatsService {

    @Autowired
    private ProductStatsMapper productStatsMapper;

    @Override
    public BigDecimal getGmv(int date) {
        return productStatsMapper.selectGMV(date);
    }

    @Override
    public Map getGmvByTm(int date, int limit) {

        //1.查询数据
        List<Map> maps = productStatsMapper.selectGmvByTm(date, limit);

        //2.创建Map存放加工后的数据
        HashMap<String, BigDecimal> resultMap = new HashMap<>();

        //3.遍历查询结果,将数据写入Map
        for (Map map : maps) {
            resultMap.put((String) map.get("tm_name"), (BigDecimal) map.get("order_amount"));
        }

        //4.返回结果数据
        return resultMap;
    }
}
